import 'package:flutter/material.dart';
import 'package:hud/hud.dart';
import 'package:top_foundation/component/date_picker/index.dart';
import 'package:top_foundation/top_foundation.dart';
import 'package:top_foundation_example/animate_image/index.dart';
import 'package:top_foundation_example/browser/index.dart';
import 'package:top_foundation_example/dash/index.dart';
import 'package:top_foundation_example/dialog_demo/index.dart';
import 'package:top_foundation_example/grouped_list/index.dart';
import 'package:top_foundation_example/horse_race_lamp/index.dart';
import 'package:top_foundation_example/splash/index.dart';
import 'package:top_foundation_example/unRead/index.dart';

import 'index.dart';

class HomeController extends GetxController {
  HomeController();

  final state = HomeState();
  GlobalKey dropDownKey = GlobalKey();

  void setupData() {
    List<HomeItemModel> data = [
      HomeItemModel(
        title: 'tabbar',
        callback: () {
          Get.to(() => SplashPage());
        },
      ),
      HomeItemModel(
        title: 'hud',
        callback: () async {
          Hud.show();
          await Future.delayed(Duration(milliseconds: 200));

          Hud.toast('我是第一个toast');
          await Future.delayed(Duration(milliseconds: 200));
          await Hud.dismiss();
          Hud.show();
          await Future.delayed(Duration(milliseconds: 1800));
          Hud.show();
          await Future.delayed(Duration(milliseconds: 5000));
          Hud.dismiss();
        },
      ),
      HomeItemModel(
        title: '日历选择器',
        callback: () {
          showCalendar(
            isRange: true,
            result: (start, end) {
              Get.log(start.toString() + '-----' + end.toString());
            },
          );
        },
      ),
      HomeItemModel(
        title: 'datePicker',
        callback: () {
          showDateDayPicker(
            result: (date, isAm) {
              Get.log(date.toString());
            },
          );
        },
      ),
      HomeItemModel(
        title: 'grouped-list',
        callback: () {
          Get.to(() => GroupedListPage(), binding: GroupedListBinding());
        },
      ),
      HomeItemModel(
        title: 'unReadMsg',
        callback: () {
          Get.to(() => const UnreadPage(), binding: UnreadBinding());
        },
      ),
      HomeItemModel(
        title: 'frameImage',
        callback: () {
          Get.to(() => const AnimateImagePage(),
              binding: AnimateImageBinding());
        },
      ),
      HomeItemModel(
        title: 'browser',
        callback: () {
          Get.to(
            () => const BrowserPage(),
            binding: BrowserBinding(),
          );
        },
      ),
      HomeItemModel(
        title: 'horse race lamp',
        callback: () {
          Get.to(
            () => const HorseRaceLampPage(),
            binding: HorseRaceLampBinding(),
          );
        },
      ),
      HomeItemModel(
        title: 'dash border',
        callback: () {
          Get.to(
            () => const DashPage(),
            binding: DashBinding(),
          );
        },
      ),
      HomeItemModel(
        title: 'select tag',
        callback: () {
          Get.to(
            () => const DialogDemoPage(),
            binding: DialogDemoBinding(),
          );
        },
      ),
    ];
    state.list = data;
    update();
  }

  /// 在 widget 内存中分配后立即调用。
  @override
  void onInit() {
    super.onInit();
  }

  /// 在 onInit() 之后调用 1 帧。这是进入的理想场所
  @override
  void onReady() {
    super.onReady();
    setupData();
  }

  /// 在 [onDelete] 方法之前调用。
  @override
  void onClose() {
    super.onClose();
  }

  /// dispose 释放内存
  @override
  void dispose() {
    super.dispose();
  }
}
